package com.mall.dao;

import com.mall.domain.ItemCat;
import com.mall.domain.Page;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 门店类别的持久层接口
 * @author : liangY
 * @date : 2021-01-04 16:48
 */
@Repository
public interface IItemCatDao {

    /**
     * 查询所有门店类别
     * @param page 分页实体类
     * @return
     */
    @Select("select * from tb_item_cat where cat_level=#{page.cat_level} and cat_name like #{page.query} limit #{page.num},#{page.size}")
    List<ItemCat> findAll(@Param("page") Page page);

    /**
     * 查询所有门店分类数量
     * @return
     */
    @Select("select count(*) from tb_item_cat where cat_level=#{cat_level}")
    Integer findTotal(Integer cat_level);

    /**
     * 更新门店分类
     * @param itemCat 门店分类实体类
     * @return
     */
    @Update("update tb_item_cat set cat_name=#{cat_name},cat_level=#{cat_level}," +
            "cat_deleted=#{cat_deleted},cat_icon=#{cat_icon},cat_location=#{cat_location},cat_desc=#{cat_desc}" +
            " where cat_id=#{cat_id}")
    Integer update(ItemCat itemCat);

    /**
     * 添加门店分类
     * @param itemCat 门店分类实体类
     * @return
     */
    @Insert("insert into tb_item_cat (cat_name,cat_level,cat_deleted,cat_icon,cat_location,cat_desc)" +
            "values(#{cat_name},#{cat_level},#{cat_deleted},#{cat_icon},#{cat_location},#{cat_desc})")
    @SelectKey(keyColumn = "cat_id", keyProperty = "cat_id", resultType = Integer.class,
            before = false, statement = {"select last_insert_id()"})
    Integer add(ItemCat itemCat);

    /**
     * 删除门店分类
     * @param cat_id 门店分类
     * @return
     */
    @Update("update tb_item_cat set cat_deleted=1 where cat_id = #{cat_id}")
    Integer del(Integer cat_id);

    @Delete("delete from tb_item_cat  where cat_id = #{cat_id}")
    Integer del1(Integer cat_id);
}
